var vm = new Vue({
    el:"#app",
    data () {
        return {
            //初始化参数
            Store:'',
            Bm:'',
            UserNo:'',
            UserName:'',
            ThemeList:[],


            formItem: {
                Store: '',
                CreateUser:'',
                Theme: '',
                CreateTime: '',
                TaskTotal: '',
                SaleTotal: '',
            },
            qformItem:{
                Store:'',
                Theme:'',
                CreateTime:''
            },
            //销售总额 销售任务 完成率
            TotalItem:{
                SaleTotalSum:'',
                TaskTotalSum:'',
                FinshRate:'',
            },
            modal1:false, //录入销售总额弹框
            columns1: [
                {
                    type: 'index',
                    title: '序号',
                    width:46,
                    align: 'center',
                },
                {
                    title: '日期',
                    key: 'CreateTime',
                    align: 'center',
                },
                {
                    title: '店面',
                    key: 'Store',
                    align: 'center',
                },
                {
                    title: '主题',
                    key: 'Theme',
                    align: 'center',
                },
                {
                    title: '销售任务',
                    key: 'TaskTotal',
                    align: 'center',
                },
                {
                    title: '销售总额',
                    key: 'SaleTotal',
                    align: 'center',
                },
            ],
            data1: []
        }
    },
    created(){
        this.initThisPage();
    },
    methods:{
        ok () {
        },
        cancel () {
        },
        queryTheme(){
            var self = this;
            $.ajax({
                url: "./goProject/queryTheme", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                type: "GET", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    var ThemeList = data.ThemeList;
                    for(var i=0;i<ThemeList.length;i++){
                        var temp = {
                            value: ThemeList[i].ThemeName,
                            label: ThemeList[i].ThemeName
                        };
                        self.ThemeList.push(temp)
                    }
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });
        },
        openmodel1(){
            var self = this;
            self.ThemeList = [];
            self.queryTheme();
            self.formItem.Store = self.Store;
            self.formItem.CreateUser = self.UserNo;
            self.modal1 = true;
        },
        //新增销售额销售任务
        saveDataTotal(){
            var self = this;
            var Store = self.formItem.Store;
            var Theme = self.formItem.Theme;
            var CreateTime = self.formItem.CreateTime;
            var TaskTotal = self.formItem.TaskTotal;
            var SaleTotal = self.formItem.SaleTotal;
            var CreateUser = self.formItem.CreateUser;
            if(Theme==""||Theme==null){
                toastr.warning("请选择活动主题");
                return false;
            }
            if(CreateTime==""||CreateTime==null){
                toastr.warning("请选择录入时间");
                return false;
            }
            if(CreateTime!=null&&CreateTime!=''){
                var tempCreateTime = new Date(CreateTime);
                CreateTime = tempCreateTime.toLocaleDateString();
            }
            if(TaskTotal==""||TaskTotal==null){
                toastr.warning("请录入销售任务");
                return false;
            }
            if(isNaN(TaskTotal)){
                toastr.warning("销售任务请输入数字");
                return false;
            }
            if(SaleTotal==""||SaleTotal==null){
                toastr.warning("请录入销售总额");
                return false;
            }
            if(isNaN(SaleTotal)){
                toastr.warning("销售总额请输入数字");
                return false;
            }
            var jsondata = {
                "Store":Store,
                "Theme":Theme,
                "CreateTime":CreateTime,
                "TaskTotal":TaskTotal,
                "SaleTotal":SaleTotal,
                "CreateUser":CreateUser,
            }
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goProject/saveDataTotal", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                type: "POST", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    if(data.Status==1){
                        toastr.success("保存成功");
                        self.formItem.Store = "";
                        self.formItem.Theme = "";
                        self.formItem.CreateTime = "";
                        self.formItem.TaskTotal = "";
                        self.formItem.SaleTotal = "";
                        self.formItem.CreateUser = "";
                    }else{
                        toastr.error("保存失败，请刷新页面后重试");
                    }
                },
                complete: function() {
                    self.querytable();
                    //请求完成的处理
                },
                error: function(data) {

                }
            });
        },
        querytable(){
            var self = this;
            var info ;
            var Store = self.qformItem.Store;
            var Theme = self.qformItem.Theme;
            var CreateTime = self.qformItem.CreateTime;
            if(CreateTime!=null&&CreateTime!=''){
                var tempCreateTime = new Date(CreateTime);
                CreateTime = tempCreateTime.toLocaleDateString();
            }
            var jsondata={"Store":Store,"Theme":Theme,"CreateTime":CreateTime};
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goProject/queryDataTotal", //请求的url地址
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                async:false,
                type: "POST", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function(data) {
                    info = eval(data.ResultList);
                    self.TotalItem.SaleTotalSum =  data.SaleTotalSum;
                    self.TotalItem.TaskTotalSum = data.TaskTotalSum;
                    if(data.FinshRate=='NaN'){
                        self.TotalItem.FinshRate = '0';
                    }else{
                        self.TotalItem.FinshRate = data.FinshRate + '%';
                    }

                },
                error: function() {},
            });
            if(info){
                self.data1 = info;
            }
        },
        // 编辑弹框
        edit(){
            this.modal1=true;
        },
        initThisPage(){
            var self = this;
            $.ajax({
                url: "./goLogin/initIndexPage", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                async:false,
                dataType: "json", //返回格式为json
                type: "GET", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    if(data.Status==0){
                        // top.location.href = "../../login.html";
                        window.location.href="../../login.html";
                    }else{
                        self.Store = data.Store;
                        self.UserNo = data.UserNo;
                        self.UserName = data.UserName;
                        self.Bm = data.Bm;
                        if(data.Store=='运营管理中心'){
                            $("#QStoreIsOrNot").attr("style","");
                        }else{
                            self.qformItem.Store = data.Store;
                            $("#QStoreIsOrNot").attr("style","display:none");
                        }
                        // if(data.Bm=='财务'||data.Bm=='副总'){
                        if(data.Bm=='副总'){
                            $("#SaveSAndRIsOrNot").attr("style","");
                        }else{
                            $("#SaveSAndRIsOrNot").attr("style","display:none");
                        }
                        self.queryTheme();
                    }
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function() {}
            });
        },

        //手机号验证
        isPoneAvailable(str) {
            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        },
    }
})